import { ref, onMounted } from 'vue';
import { listBrand } from '@/api/iot/brand';

export function useBrandListOptions() {
  const brandListOptions = ref<{ label: string; value: string | number }[]>([]);
  const loading = ref(false);

  const loadOptions = async () => {
    loading.value = true;
    try {
      const res = await listBrand(); // 获取全部项目
      const options = res.rows.map((item) => ({
        label: item.brandName, // 显示名
        value: item.brandId // 实际值
      }));
      brandListOptions.value = options;
    } finally {
      loading.value = false;
    }
  };

  // 自动加载（可选）
  onMounted(() => {
    loadOptions();
  });

  return {
    brandListOptions,
    loading,
    reload: loadOptions // 手动刷新
  };
}
